<template>
  <div id="app-container" style="margin: 10px 50px">
    <div>
      <div style="display: flex; align-items: center; justify-content: center;">
        <el-avatar
          shape="square"
          :size="100"
          :fit="fit"
          :src="student.headUrl"
        ></el-avatar>
        <span style="margin-left: 30px">学生姓名: {{ student.username }}</span>
        <span style="margin-left: 30px">班级信息：{{ student.fullInfo }}</span>
      </div>
      <el-divider><i class="el-icon-mobile-phone"></i></el-divider>
    </div>
    <!-- 判断是否绑定学院信息 如果没绑定就不让上传实习报告-->
    <div
      v-if="
         student.year == null  ||
         student.className == null ||
          student.classNo == null ||
          student.teacherId == null ||
        student.year == 0 ||
          student.className == 0 ||
          student.classNo == 0 ||
          student.teacherId == 0
      "
    >
      <el-tag type="danger"
        >您还未绑定学院班级信息或指导老师信息，请先去绑定。<el-link
          href="/#/studentInfo/list"
          type="primary"
          >绑定</el-link
        ></el-tag
      >
    </div>

    <!-- 想在这里添加 不完善实习公司的信息 就不能进行提交 -->
    <div
      v-if="!isWriteEnv"
    >
      <el-tag type="danger"
        >您还未填写实习信息,请先去填写信息。<el-link
          href="/#/work/list"
          type="primary"
          >绑定</el-link
        ></el-tag
      >
    </div>

    <!-- 已绑定信息 未上传实习信息 -->
    <div v-else-if="student.log == false && isVisibale == true">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span style="color: red;font-size: 23px;">请上传您的实习日志：</span>
        </div>
        <el-form label-position="right" label-width="170px">
        <el-form-item label="文件">
          <el-upload
            :multiple="false"
            :on-success="onUploadSuccess"
            :action="'http://localhost:8222/user/oss/file/upload'"
            class="upload-demo"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              请上传前仔细检查，上传后不可更改！
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      </el-card>
    
    </div>

    <!-- 已绑定信息 已传实习信息 未查看 -->
    <div v-if="student.log == true && student.internshipLog.status == 0 && isVisibale == true">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span style="color: red;font-size: 23px;">已上传实习日志，老师未查看</span>
        </div>

      </el-card>
    </div>


    <!-- 已查看 已评分 -->
    <div v-else-if="student.log == true && student.internshipGrade != null && isVisibale == true">
      
      <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span style="color: red;font-size: 23px;">老师查看了您的实习日志，并进行了批改</span>
        </div>
        <span>您的成绩为： {{student.internshipGrade.grade}}</span>
      </el-card>
    </div>
    <!-- 打回 原因 -->
    <div v-else-if="student.log == true && student.internshipLog.status == -1 && isVisibale == true">
        <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span style="color: red;font-size: 23px;">您的实习日志已被打回</span>
        </div>
        <span>原因为： {{student.internshipLog.comment}}，请修改后重新上传！</span>
        <!-- 重新上传 -->
        <el-form label-position="right" label-width="170px">
        <el-form-item label="文件">
          <el-upload
            :multiple="false"
            :on-success="onUploadSuccess"
            :action="'http://localhost:8222/user/oss/file/upload'"
            class="upload-demo"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              请上传前仔细检查，上传后不可更改！
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      </el-card>
    </div>
        <!-- 已查看 未评分 -->
        <div v-else-if="student.log == true && student.internshipGrade == null && isVisibale == true">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span style="color: red;font-size: 23px;">上传实习日志，老师已查看但未评分</span>
        </div>

      </el-card>
    </div>

        <!-- 静等老师查阅批改 -->
        <div v-if="isVisibale == false">
        <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span style="color: red;font-size: 23px;">您的实习日志已提交</span>
        </div>
        <span>静等老师批改，GOOD LUCK!!</span>
      </el-card>
    </div>

  </div>
</template>

<script>
import studentApi from "@/api/student";
import logApi from "@/api/log";

export default {
  data() {
    return {
      isVisibale: true,
      isWriteEnv: false,
      student: {},
      fit: "cover"
    };
  },
  methods: {
    onUploadSuccess(response, file, fileList){

        this.student.fileName = file.name;
        this.student.fileUrl = file.response.data.url;
        logApi.uploadLog(this.student).then(resp=>{
          this.isVisibale = false;
        })
        
    }
  },
  created() {
    studentApi.getStudentByUsername().then(resp => {
      this.student = resp.data.student;
      console.log(resp.data.student);
    });
    this.student.name = "测试";
    console.log(this.student.name);

    logApi.judgeSaveEnpInfo().then(resp => {
      console.log(resp,"测试数据");
      console.log(this.isWriteEnv,"isWriteEnv before");
      this.isWriteEnv = resp.data.writeEnv
      console.log(this.isWriteEnv,"isWriteEnv after");
    })

  },

  

};
</script>

<style></style>
